#include <QCoreApplication>
#include <QStringList>
#include <QImage>
#include <QRegExp>
#include <QFileInfo>

#include <QDebug>

int main(int argc, char **argv) {
	QCoreApplication a(argc, argv);
	
	QStringList args = a.arguments();
	if (args.size() < 2) {
		qDebug() << "Please call bmp2h <image>.";
	}
	
	QString path(args.at(1));
	QImage im;
	if (!im.load(path)) {
		qDebug() << "Invalid path or image" << args.at(0) << ".";
	}
	
	im = im.convertToFormat(QImage::Format_Mono);
	QFileInfo info(path);
	QString output("../src/background.h");
	
	QFile data(output);
	if (data.open(QFile::WriteOnly | QFile::Truncate)) {
		QTextStream out(&data);
		out << "BYTE background[] = {\n";
		const uchar *scanline = im.constScanLine(0);
		for (int i = 0; i < im.byteCount(); ++i) {
			for (int k = 7; k >= 0; --k) {
				if (scanline[i] & (1 << k)) {
					out << "0xFF, ";
				} else {
					out << "0x00, ";
				}
			}
		}
		out << "\n};\n";
	}
	
	
	
	return 0;
}
